package com.itcast.jobs;

import com.itcast.constant.RedisConstant;
import com.itcast.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class ClearImgJob {

    @Autowired
    private JedisPool jedisPool;
    public void clearImg(){
        Set<String> set = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        if (set!=null){
            for (String pickName : set) {
                /*删除七牛云上的图片*/
                QiniuUtils.deleteFileFromQiniu(pickName);
                /*从redis集合中删除图片名称*/
                  jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES, pickName);
                System.out.println("杰尼龟清楚垃圾图片！！!"+pickName);
            }
        }
    }
}
